package com.demo.v2;

public class RbTree<T extends Comparable<T>> {

    private String message = "key can't null";
    /**
     * 根节点
     */
    private RbtNode<T> mRoot;

    /**
     * 查找红黑树中指定为key的节点
     */
    public RbtNode<T> search(T key) throws Exception {
        return search(mRoot, key);
    }

    private RbtNode<T> search(RbtNode<T> x, T key) throws Exception {
        if(x == null){
            throw new Exception(message);
        }
        int cmp = key.compareTo(x.key);
        if(cmp > 0){
            return search(x.right, key);
        }else if(cmp < 0){
            return search(x.left, key);
        }else{
            return x;
        }
    }

    /**
     * 插入key值到红黑树
     */
    private void insert(T key){
        //TODO wangshengkai
    }

    /**
     * 打印红黑树
     */
    private void print(){
        //TODO wangshengkai
    }
}
